#! /bin/bash
#SQOOP_HOME=/opt/cloudera/parcels/CDH-6.2.1-1.cdh6.2.1.p0.1425774/bin/sqoop
export LANG=zh_CN.UTF-8
SQOOP_HOME=/usr/bin/sqoop
if [[ $1 == "" ]];then
   TD_DATE=`date -d '1 days ago' "+%Y-%m-%d"`
else
   TD_DATE=$1
fi

echo '========================================'
echo '==============开始全量导入==============='
echo '========================================'

# customer_relationship（客户申请表）
# 全量导入
sqoop import \
--connect "jdbc:mysql://hadoop01:3306/scrm" \
--username root \
--password 123456 \
--query "select *,'2024-09-16' as dt from customer_relationship where true and  \$CONDITIONS" \
--hcatalog-database ods \
--hcatalog-table customer_relationship \
-m 1
wait

# # 增量导入
# sqoop import \
# --connect jdbc:mysql://hadoop01:3306/scrm --username root \
# --password 123456 \
# --query "select *,'${TD_DATE}' as dt from customer_relationship where true and \$CONDITIONS" \
# --hcatalog-database ods \
# --hcatalog-table customer_relationship \
# -m 1
# wait


# itcast_clazz（报名课程表）
# 全量导入
/usr/bin/sqoop import \
--connect jdbc:mysql://hadoop01:3306/scrm \
--username root \
--password 123456 \
--query "select *,'2024-09-16' as dt from itcast_clazz where true and \$CONDITIONS" \
--hcatalog-database ods \
--hcatalog-table itcast_clazz \
-m 1
wait

# # 增量导入
# sqoop import \
# --connect jdbc:mysql://hadoop01:3306/scrm --username root \
# --password 123456 \
# --query "select *,'${TD_DATE}' as dt from itcast_clazz where true and \$CONDITIONS" \
# --hcatalog-database ods \
# --hcatalog-table itcast_clazz \
# -m 1
# wait


# employee(员工表)
# 全量导入
/usr/bin/sqoop import \
--connect jdbc:mysql://hadoop01:3306/scrm \
--username root \
--password 123456 \
--query "select *,'2024-09-16' as dt from employee where true and \$CONDITIONS" \
--hcatalog-database ods \
--hcatalog-table employee \
-m 1
wait

# # 增量导入
# sqoop import \
# --connect jdbc:mysql://hadoop01:3306/scrm --username root \
# --password 123456 \
# --query "select *,'${TD_DATE}' as dt from employee where true and \$CONDITIONS" \
# --hcatalog-database ods \
# --hcatalog-table employee \
# -m 1
# wait


# scrm_department(部门表)
# 全量导入
/usr/bin/sqoop import \
--connect jdbc:mysql://hadoop01:3306/scrm \
--username root \
--password 123456 \
--query "select *,'2024-09-16' as dt from scrm_department where true and \$CONDITIONS" \
--hcatalog-database ods \
--hcatalog-table scrm_department \
-m 1
wait

# # 增量导入
# sqoop import \
# --connect jdbc:mysql://hadoop01:3306/scrm --username root \
# --password 123456 \
# --query "select *,'${TD_DATE}' as dt from scrm_department where true and \$CONDITIONS" \
# --hcatalog-database ods \
# --hcatalog-table scrm_department \
# -m 1
# wait


